﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SistemadeEstágios.Model;

namespace SistemadeEstágios.DAL
{
    public class CursosBD : BaseBD
    {

        public Cursos Buscar(int codigo)
        {
            Cursos obj = null;
            string query = @"Select * From Curso Where codigo = @codigo";

            try
            {
                oDbManager.OpenConnection();

                oDbManager.AddParameter("@codigo", codigo);

                oDbManager.ExecuteReader(query);

                if (oDbManager.DBReader.Read())
                {
                    obj = new Cursos();

                    obj.Codigo = Int32.Parse(oDbManager.DBReader["codigo"].ToString());
                    obj.Nome = oDbManager.DBReader["nome"].ToString();
                    
                }
            }
            finally
            {
                oDbManager.CloseConnection();
            }
            return obj;
        }

        public List<Cursos> Buscar()
        {
            List<Cursos> lst = null;
            Cursos obj = null;
            string query = @"Select * From Curso";

            try
            {
                oDbManager.OpenConnection();

                oDbManager.ExecuteReader(query);

                while (oDbManager.DBReader.Read())
                {
                    if (lst == null)  lst = new List<Cursos>();

                    obj = new Cursos();

                    obj.Codigo = Int32.Parse(oDbManager.DBReader["codigo"].ToString());
                    obj.Nome = oDbManager.DBReader["nome"].ToString();

                    lst.Add(obj);
                }
            }
            finally
            {
                oDbManager.CloseConnection();
            }
            return lst;
        }
    }
}
